{include file="public/header" /}
<title></title>
</head>

<body>
	<article class="page-container">
		<form class="form form-horizontal" id="form-admin-add" method="post">
			<div class="row cl">
				<input type="text"  value="{$data.id}" id="id" style="display: none;">
				<label class="form-label col-xs-4 col-sm-3">省代列表：</label>
		        <div class="formControls col-xs-8 col-sm-9">
					<select name="agency_id" id='agency_id' onchange="sheng_change(this.options[this.options.selectedIndex].value)" style="width: 235px;height: 30px;">
						<option value="0">选择省代</option>
						{volist name="info_oem" id="vo"}
							<option value="{$vo.id}">{$vo.user_name}</option>
						{/volist}
					</select>
				</div>
		    </div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">市代列表：</label>
		        <div class="formControls col-xs-8 col-sm-9">
					<select name="city_id" id="city_id" style="width: 235px;height: 30px;">
						<option value="0">选择市代</option>
					</select>
				</div>
		    </div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">商家编号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.tj_agent}" placeholder="" id="tj_agent" name="tj_agent">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">推荐人编号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.level}" placeholder="" id="level" name="level">
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" id='tijiao' type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>
	{include file="public/footer" /}
	<script type="text/javascript">
		$(function() {
			$('.skin-minimal input').iCheck({
				checkboxClass: 'icheckbox-blue',
				radioClass: 'iradio-blue',
				increaseArea: '20%'
			});

			$('#tijiao').click(function() {
				var agency_id = $("#agency_id").val();
				var city_id = $("#city_id").val();
				if(agency_id=='0'){
					layer.msg("请选择省代");
					return false;
				}
				if(city_id=='0'){
					layer.msg("请选择市代");
					return false;
				}
				
				$.ajax({
					type: 'post',
					data: {
						id				: $('#id').val(),
						tj_agent		: $('#tj_agent').val(),
						level			: $('#level').val(),
						agency_id		: $('#agency_id').val(),
						city_id			: $('#city_id').val()						
					},
					url: "{:url('accounts/user_update')}",
					success: function(data) {
						if(data.code == 200) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						}

					},
					error: function(XmlHttpRequest, textStatus, errorThrown) {
						layer.msg(data.msg, {
							icon: 1,
							time: 1000
						});
					}
				});
			});
		});
		
		
	//切换省代
	function sheng_change(id){
		 $.ajax({
             	type:"post",
                url:"{:url('accounts/sdlist')}",
                data: {
                	id:id
                },
                success:function(data){  
                	var sdlist = data.data;
                    var select_htm = '';
					if(sdlist && sdlist.length<1){
						select_htm = "<option value='0'>选择市代</option>";
					}else{
						for(var i=0;i<sdlist.length;i++){
							select_htm += "<option value='"+sdlist[i].id+"'>"+sdlist[i].user_name+"</option>";
						}
					}

					$('#city_id').empty();
					$('#city_id').append(select_htm);

                },error:function(data){
                	var a = data;
                }
        });
	}
	</script>